<?php
/**
 * Created by PhpStorm.
 * User: 123
 * Date: 2020/7/30
 * Time: 13:11
 */

namespace app\api\controller;



use app\service\MemberService;
use think\App;
use think\Controller;
use think\Db;

/**
 * 首页
 * @author   juzi
 * @blog    https://blog.csdn.net/juziaixiao
 * @version  0.0.1
 * @datetime 2020年7月22日10:57:35
 */
class Index extends Controller
{
    /**
     * 构造方法.
     * @author   juzi
     * @blog     https://blog.csdn.net/juziaixiao
     * @version  1.0.0
     * @datetime 2020年7月10日09:35:10
     */
     public function __construct(App $app = null)
     {
         parent::__construct($app);
     }


    /**
     * 云盟时代.
     * @author   juzi
     * @blog     https://blog.csdn.net/juziaixiao
     * @version  1.0.0
     * @datetime 2020年7月10日09:35:10
     */
    public function LeegameStatus()
    {
        $params=input();

        $where=[
            ['mo.receive_phone' ,'=',$params['phone']],
            ['mo.pay_status' ,'=',1],
            ['mo.add_integral' ,'=',1],
        ];
        $re=Db::name('member_order')
            ->alias('mo')
            ->join(['member'=>'m'], 'm.id=mo.member_id')
//            ->join(['member_orderdetail'=>'mod'], 'mo.id=mod.order_id')
            ->where($where)->field('mo.pay_price money,mo.create_time,total_price total_money,time,mo.id order_id')->select();
        Db::name('member_order')
            ->alias('mo')
            ->join(['member'=>'m'], 'm.id=mo.member_id')
//            ->join(['member_orderdetail'=>'mod'], 'mo.id=mod.order_id')
            ->where($where)->update(['mo.add_integral'=>2]);
        //Db::name('member_order')->update(['add_integral'=>2]);
        $a=empty($re)?[]:$re;
        return json($a);
    }

    /**
     * 跳转下载地址.
     * @author   juzi
     * @blog     https://blog.csdn.net/juziaixiao
     * @version  1.0.0
     * @datetime 2020年7月10日09:35:10
     */
    public function DownLoadApk(){
        $edition = Db::table('edition')->field('url,id')->order("id desc")->find();
        $url = $edition['url'];
//        $url = "http://yun.youpilive.com/version/bridge.apk";
        $id = $edition['id'];
        if(!empty($url)){
            #加下载记录
            $res = Db::table("log_download")->insert(array("create_time"=>date("Y-m-d H:i:s"),"edition_id"=>$id));

            if($res){
                #跳转到下载地址
                $this->redirect($url);//app的下载地址
            }
        }
    }

    function demo(){
        $status= MemberService::getSmsCode('13154199291');
        // 状态
        if($status['status'])
        {
            return json(DataReturn('发送成功', 0,['code'=>$status['num']]));
        } else {
            return json(DataReturn('发送失败', 0,['code'=>$status['num']]));

        }


    }

    public function test(){
        return $this->fetch('alipay/indexre');
    }


}